﻿/*****************************************************************//**
  * @file   VAOneXMLAdaptorConnections.h
  * @brief  VAOne读写连接器适配器
  *
  * @author lilongyuan (lilongyuan@diso.cn)
  * @date   2025-01-18
  *********************************************************************/
#ifndef VAONEXMLADAPTORCONNECTIONS_H
#define VAONEXMLADAPTORCONNECTIONS_H

#include "FITKAbstractVAOneXMLAdaptor.h"
#include "FITK_Component/FITKAcousticsPhysics/FITKAcousticsAbstractLoad.h"

namespace Acoustics
{
    class FITKAbstractJunction;
    class FITKAbstractSEASubSys;
    class FITKSEAJunctionPoint;
    class FITKSEAJunctionLine;
    class FITKSEAJunctionArea;
    class FITKLoadExcitationForceMoments;
    class FITKSEASubSysSemiInfiniteFluid;
    class FITKSEASubSysSEIFConnectedSubSys;
    //class FITKAcousticsAbstractLoad;
}

namespace IO
{
    /**
     * @brief   XML读写适配器，用于读写连接器数据
     * @author  lilongyuan (lilongyuan@diso.cn)
     * @date    2025-01-18
     */
    class FITKVAOneXMLIOAPI VAOneXMLAdaptorConnections : public FITKAbstractVAOneXMLAdaptor
    {
        FITKCLASS(IO, VAOneXMLAdaptorConnections);

    public:
        /**
         * @brief     写出连接对象和连接的子系统模板
         * @param[i]  parentNode 父节点，connectToObject 连接对象，subSystemData 子系统数据
         * @return    是否执行成功
         * @author    lilongyuan (lilongyuan@diso.cn)
         * @date      2025-01-21
         */
        template <typename T,typename S>
        bool writeConnecttoAndSubsystem(rapidxml::xml_node<char>* parentNode, T connectToObject, S subSystemData)
        {
            // parentNode、connectToObject和subSystemData不能为空
            if (parentNode == nullptr || connectToObject == nullptr || subSystemData == nullptr) return false;

            // connected_to
            rapidxml::xml_node<char>* ConnectedToChild = createNodeElement(parentNode, "connected_to", connectToObject->getDataObjectName());
            if (nullptr == ConnectedToChild) return false;
            
            // subsystem
            rapidxml::xml_node<char>* subSystemChild = createNodeElement(parentNode, "subsystem", subSystemData->getDataObjectName());
            if (nullptr == subSystemChild) return false;

            return true;
        }

        /**
         * @brief   构造函数
         * @author  lilongyuan (lilongyuan@diso.cn)
         * @date    2025-01-18
         */
        explicit VAOneXMLAdaptorConnections() = default;

        /**
         * @brief   析构函数
         * @author  lilongyuan (lilongyuan@diso.cn)
         * @date    2025-01-18
         */
        ~VAOneXMLAdaptorConnections() = default;

        /**
         * @brief   适配器读数据
         * @return  是否执行成功
         * @author  lilongyuan (lilongyuan@diso.cn)
         * @date    2025-01-18
         */
        bool adaptR() override;

        /**
         * @brief   适配器写数据
         * @return  是否执行成功
         * @author  lilongyuan (lilongyuan@diso.cn)
         * @date    2025-01-18
         */
        bool adaptW() override;

    private:
        /**
         * @brief     读取点结连接数据接口
         * @param[i]  node PointConnection节点
         * @return    是否执行成功
         * @author    lilongyuan (lilongyuan@diso.cn)
         * @date      2025-01-18
         */
        bool readPointConnection(rapidxml::xml_node<char>* node);

        /**
         * @brief     读取线结连接数据接口
         * @param[i]  node LineConnection节点
         * @return    是否执行成功
         * @author    lilongyuan (lilongyuan@diso.cn)
         * @date      2025-01-18
         */
        bool readLineConnection(rapidxml::xml_node<char>* node);

        /**
         * @brief     读取区结连接数据接口
         * @param[i]  node AreaConnection节点
         * @return    是否执行成功
         * @author    lilongyuan (lilongyuan@diso.cn)
         * @date      2025-01-18
         */
        bool readAreaConnection(rapidxml::xml_node<char>* node);

        /**
         * @brief     读取半无限流体连接数据接口
         * @param[i]  node SinkConnection节点
         * @return    是否执行成功
         * @author    lilongyuan (lilongyuan@diso.cn)
         * @date      2025-01-18
         */
        bool readSinkConnection(rapidxml::xml_node<char>* node);

        /**
         * @brief     读取负载连接数据接口
         * @param[i]  node LoadConnection节点
         * @return    是否执行成功
         * @author    lilongyuan (lilongyuan@diso.cn)
         * @date      2025-01-18
         */
        bool readLoadConnection(rapidxml::xml_node<char>* node);

        /**
         * @brief     读取SEA点结连接数据
         * @param[i]  node ShellPointConnection和BeamPointConnection节点，name节点名称
         * @return    是否执行成功
         * @author    lilongyuan (lilongyuan@diso.cn)
         * @date      2025-01-20
         */
        bool readSEAPointConnectionData(rapidxml::xml_node<char>* node, QString name);

        /**
         * @brief     读取FE点结连接数据
         * @param[i]  node FESSPointConnection节点
         * @return    是否执行成功
         * @author    lilongyuan (lilongyuan@diso.cn)
         * @date      2025-01-18
         */
        bool readFESSPoint(rapidxml::xml_node<char>* node);

        /**
         * @brief     读取线结连接数据
         * @param[i]  node BeamLineConnection节点，name节点名称
         * @return    是否执行成功
         * @author    lilongyuan (lilongyuan@diso.cn)
         * @date      2025-01-20
         */
        bool readLineConnectionData(rapidxml::xml_node<char>* node, QString name);

        /**
         * @brief     读取区结连接数据
         * @param[i]  node BeamLineConnection或ShellLineConnection节点，nsmr 节点名称
         * @return    是否执行成功
         * @author    lilongyuan (lilongyuan@diso.cn)
         * @date      2025-01-20
         */
        bool readAreaConnectionData(rapidxml::xml_node<char>* node, QString name);

        /**
         * @brief     读取半无限流体连接数据
         * @param[i]  node BeamSinkConnection或ShellSinkConnection或CavitySinkConnection节点，name 节点名称
         * @return    是否执行成功
         * @author    lilongyuan (lilongyuan@diso.cn)
         * @date      2025-01-18
         */
        bool readSinkConnectData(rapidxml::xml_node<char>* node, QString name);

        /**
         * @brief     读取点载荷连接数据
         * @param[i]  node BeamPointLoadConnection或ShellPointLoadConnection节点，name 节点名称
         * @return    是否执行成功
         * @author    lilongyuan (lilongyuan@diso.cn)
         * @date      2025-01-18
         */
        bool readPointLoadData(rapidxml::xml_node<char>* node, QString name);

        /**
         * @brief     读取用户自定义载荷连接数据
         * @param[i]  node UserDefinedLoadConnection节点
         * @return    是否执行成功
         * @author    lilongyuan (lilongyuan@diso.cn)
         * @date      2025-01-18
         */
        bool readUserDefLoad(rapidxml::xml_node<char>* node);

        /**
         * @brief     读取用户自定义连接数据
         * @param[i]  node UserDefinedConnection节点
         * @return    是否执行成功
         * @author    lilongyuan (lilongyuan@diso.cn)
         * @date      2025-01-18
         */
        bool readUserDefinedConnection(rapidxml::xml_node<char>* node);

        /**
         * @brief     写出点结连接数据接口
         * @param[i]  node Connections节点
         * @return    是否执行成功
         * @author    lilongyuan (lilongyuan@diso.cn)
         * @date      2025-01-18
         */
        bool writePointConnection(rapidxml::xml_node<char>* node);

        /**
         * @brief     写出线结连接数据接口
         * @param[i]  node Connections节点
         * @return    是否执行成功
         * @author    lilongyuan (lilongyuan@diso.cn)
         * @date      2025-01-18
         */
        bool writeLineConnection(rapidxml::xml_node<char>* node);

        /**
         * @brief     写出区结连接数据接口
         * @param[i]  node Connections节点
         * @return    是否执行成功
         * @author    lilongyuan (lilongyuan@diso.cn)
         * @date      2025-01-18
         */
        bool writeAreaConnection(rapidxml::xml_node<char>* node);

        /**
         * @brief     写出半无限流体连接数据接口
         * @param[i]  node Connections节点
         * @return    是否执行成功
         * @author    lilongyuan (lilongyuan@diso.cn)
         * @date      2025-01-18
         */
        bool writeSinkConnection(rapidxml::xml_node<char>* node);

        /**
         * @brief     写出负载连接数据接口
         * @param[i]  node Connections节点
         * @return    是否执行成功
         * @author    lilongyuan (lilongyuan@diso.cn)
         * @date      2025-01-18
         */
        bool writeLoadConnection(rapidxml::xml_node<char>* node);

        /**
         * @brief     写出用户自定义载荷连接数据接口
         * @param[i]  node Connections节点
         * @return    是否执行成功
         * @author    lilongyuan (lilongyuan@diso.cn)
         * @date      2025-01-21
         */
        bool writeUserDefLoad(rapidxml::xml_node<char>* node);

        /**
         * @brief     写出SEA梁点结连接数据
         * @param[i]  node Connections节点，pointData SEA点结数据对象
         * @return    是否执行成功
         * @author    lilongyuan (lilongyuan@diso.cn)
         * @date      2025-01-20
         */
        bool writeSEABeamPointConnectionData(rapidxml::xml_node<char>* node, Acoustics::FITKSEAJunctionPoint* pointData);

        /**
         * @brief     写出SEA板点结连接数据
         * @param[i]  node Connections节点，pointData SEA点结数据对象
         * @return    是否执行成功
         * @author    lilongyuan (lilongyuan@diso.cn)
         * @date      2025-01-20
         */
        bool writeSEAShellPointConnectionData(rapidxml::xml_node<char>* node, Acoustics::FITKSEAJunctionPoint* pointData);

        /**
         * @brief     写出FESSPoint节点数据
         * @param[i]  node Connections节点，forceMomentsData 力和力矩数据对象
         * @return    是否执行成功
         * @author    lilongyuan (lilongyuan@diso.cn)
         * @date      2025-01-18
         */
        bool writeFESSPoint(rapidxml::xml_node<char>* node, Acoustics::FITKLoadExcitationForceMoments* forceMomentsData);

        /**
         * @brief     写出SEA梁线结连接数据
         * @param[i]  node Connections节点，lineData SEA线结数据对象
         * @return    是否执行成功
         * @author    lilongyuan (lilongyuan@diso.cn)
         * @date      2025-01-21
         */
        bool writeSEABeamLineConnectionData(rapidxml::xml_node<char>* node, Acoustics::FITKSEAJunctionLine* lineData);

        /**
         * @brief     写出SEA板线结连接数据
         * @param[i]  node Connections节点，lineData SEA线结数据对象
         * @return    是否执行成功
         * @author    lilongyuan (lilongyuan@diso.cn)
         * @date      2025-01-21
         */
        bool writeSEAShellLineConnectionData(rapidxml::xml_node<char>* node, Acoustics::FITKSEAJunctionLine* lineData);

        /**
         * @brief     写出SEA声腔区结连接数据
         * @param[i]  node Connections节点，areaData SEA区结数据对象
         * @return    是否执行成功
         * @author    lilongyuan (lilongyuan@diso.cn)
         * @date      2025-01-21
         */
        bool writeSEACavityAreaConnectionData(rapidxml::xml_node<char>* node, Acoustics::FITKSEAJunctionArea* areaData);

        /**
         * @brief     写出SEA板区结连接数据
         * @param[i]  node Connections节点，areaData SEA区结数据对象
         * @return    是否执行成功
         * @author    lilongyuan (lilongyuan@diso.cn)
         * @date      2025-01-21
         */
        bool writeSEAShellAreaConnectionData(rapidxml::xml_node<char>* node, Acoustics::FITKSEAJunctionArea* areaData);

        /**
         * @brief     写出半无限流体连接数据
         * @param[i]  node 节点,subSystemData 连接的子系统数据，sinkData 半无限流体数据，sinkConnectionData 半无限流体连接数据
         * @return    是否执行成功
         * @author    lilongyuan (lilongyuan@diso.cn)
         * @date      2025-01-21
         */
        bool writeSinkConnectData(rapidxml::xml_node<char>* node, Acoustics::FITKAbstractSEASubSys* subSystemData, Acoustics::FITKSEASubSysSemiInfiniteFluid* sinkData, Acoustics::FITKSEASubSysSEIFConnectedSubSys* sinkConnectionData);

        /**
         * @brief     写出点载荷连接数据
         * @param[i]  node 节点，data 点力数据，subSysData 子系统数据
         * @return    是否执行成功
         * @author    lilongyuan (lilongyuan@diso.cn)
         * @date      2025-01-21
         */
        bool writePointLoadData(rapidxml::xml_node<char>* node, Acoustics::FITKLoadExcitationForceMoments* data, Acoustics::FITKAbstractSEASubSys* subSysData);

        /**
         * @brief     写出SEA用户自定义载荷连接数据
         * @param[i]  node Connections节点，data 载荷数据
         * @return    是否执行成功
         * @author    lilongyuan (lilongyuan@diso.cn)
         * @date      2025-01-21
         */
        bool writeSEAUserDefLoadData(rapidxml::xml_node<char>* node, Acoustics::FITKAcousticsAbstractLoad* data);

        /**
         * @brief     写出FE用户自定义载荷连接数据
         * @param[i]  node Connections节点，data 载荷数据
         * @return    是否执行成功
         * @author    lilongyuan (lilongyuan@diso.cn)
         * @date      2025-01-21
         */
        bool writeFEUserDefLoadData(rapidxml::xml_node<char>* node, Acoustics::FITKAcousticsAbstractLoad* data);

        /**
         * @brief     写出用户自定义连接数据
         * @param[i]  node Connections节点
         * @return    是否执行成功
         * @author    lilongyuan (lilongyuan@diso.cn)
         * @date      2025-01-18
         */
        bool writeUserDefinedConnection(rapidxml::xml_node<char>* node);

    private:
        /**
         * @brief     通过节点获取连接对象名称
         * @param[i]  node 节点
         * @return    QString
         * @author    lilongyuan (lilongyuan@diso.cn)
         * @date      2025-01-18
         */
        QString getConnectedToNameByNode(rapidxml::xml_node<char>* node);

        /**
         * @brief     通过节点获取交点数据
         * @param[i]  node 节点
         * @return    Acoustics::FITKSEAAbstractJunction*
         * @author    lilongyuan (lilongyuan@diso.cn)
         * @date      2025-01-18
         */
        Acoustics::FITKAbstractJunction* getJunctionData(rapidxml::xml_node<char>* node);

        /**
         * @brief     通过节点获取载荷数据
         * @param[i]  node 节点
         * @return    Acoustics::FITKAcousticsAbstractLoad*
         * @author    lilongyuan (lilongyuan@diso.cn)
         * @date      2025-01-18
         */
        Acoustics::FITKAcousticsAbstractLoad* getLoadData(rapidxml::xml_node<char>* node);

        /**
         * @brief     通过节点获取子系统管理器数据
         * @param[i]  node 节点
         * @return    Acoustics::FITKAbstractSEASubSys*
         * @author    lilongyuan (lilongyuan@diso.cn)
         * @date      2025-01-18
         */
        Acoustics::FITKAbstractSEASubSys* getSEASubSysData(rapidxml::xml_node<char>* node);

        /**
         * @brief     通过节点获取连接的SEA子系统ID
         * @param[i]  node 节点
         * @return    int
         * @author    lilongyuan (lilongyuan@diso.cn)
         * @date      2025-01-18
         */
        int getConnectSEASubSystemId(rapidxml::xml_node<char>* node);

        /**
         * @brief     通过节点获取连接的FE子系统ID
         * @param[i]  node 节点
         * @return    int
         * @author    lilongyuan (lilongyuan@diso.cn)
         * @date      2025-01-18
         */
        int getConnectFESubSystemId(rapidxml::xml_node<char>* node);

        /**
         * @brief     写出SEA载荷列表数据
         * @param[i]  node Connections节点，type 载荷类型
         * @return    bool
         * @author    lilongyuan (lilongyuan@diso.cn)
         * @date      2025-01-18
         */
        bool writeSEALoadListData(rapidxml::xml_node<char>* node, Acoustics::FITKAcousticsAbstractLoad::AcousticsLoadType type);

        /**
         * @brief     写出FE载荷列表数据
         * @param[i]  node Connections节点，type 载荷类型
         * @return    bool
         * @author    lilongyuan (lilongyuan@diso.cn)
         * @date      2025-01-18
         */
        bool writeFELoadListData(rapidxml::xml_node<char>* node, Acoustics::FITKAcousticsAbstractLoad::AcousticsLoadType type);
    };
    Register2FITKIOAdaptorFactory(VAOneXML, Connections, VAOneXMLAdaptorConnections)
}

#endif // VAONEXMLADAPTORCONNECTIONS_H

